<?php

namespace addons\qingdongams\model;

use think\Db;
use think\Exception;
use think\Model;
use traits\model\SoftDelete;

/**
 *报价单产品
 */
class QuoteProduct Extends Model {

    protected $name = 'qingdongams_quote_product';
    // 开启自动写入时间戳字段
    protected $autoWriteTimestamp = false;


    public function getConfigAttr($value)
    {

        return json_decode($value,true);
    }

    //产品
    public function product() {
        return $this->belongsTo(Product::class, 'product_id', 'id')
            ->with('productType')
            ->field('id,name,img,num,unit,price as unit_price,description,type_id')
            ->bind('name,img,num,unit,unit_price,description,product_type');
    }

    //产品详情
    public function productinfo(){
        return $this->belongsTo(Product::class,'product_id','id')
            ->field('id,goods_id,name,type,unit,price,cost_price')->with(['goods']);
    }
}
